import { IAuthGuardMiddlewareConfig } from '@todo/core';
import { UserModel } from '../user/models/user.model.ts';
import { Container } from 'inversify';
import { AUTH_ROUTES } from './config/routes.ts';

export const authGuard: IAuthGuardMiddlewareConfig['auth'] = (_router) => {
  const container = _router.getDependencies()['di'] as Container;

  const userModel = container.get<UserModel>(UserModel);

  return {
    auth: userModel.authenticated,
    fallbackRoute: AUTH_ROUTES.LOGIN,
  };
};
